package cn.flying.cloud.system.view;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.base.common.vo.layui.XmSelect;
import cn.flying.cloud.system.common.service.CodeService;
import cn.flying.cloud.system.position.entity.SysPostInfo;
import cn.flying.cloud.system.position.service.SysPostInfoService;
import cn.flying.cloud.system.service.SysPositionService;

/**
 * @description: 岗位请求处理
 * @author: admin
 * @date: 2022年06月05日 20:21
 * @version: 1.0
 */
@Controller
@RequestMapping("/sys/position/")
public class SysPositionViewController {

    @Resource
    private SysPostInfoService sysPostInfoService;
    @Resource
    private SysPositionService sysPositionService;
    @Resource
    private CodeService codeService;

    /**
     * 跳转到列表页面
     *
     * @return
     */
    @RequestMapping("index")
    public String list(Model model) {
        Map<String, String> statusList = codeService.getCodeList("status");
        model.addAttribute("statusList", statusList);
        return "sys/position/index";
    }

    /**
     * 获取岗位下拉框数据 xm-select
     *
     * @param
     * @return
     */
    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    @ResponseBody
    public Rt<List<XmSelect>> getSelectList() {
        List<XmSelect> list = sysPositionService.getPositionSelectList();
        return Rt.success(list);
    }

    /**
     * 新增/修改页面
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("turn/edit")
    public String turnEdit(Long id, Model model) {
        if (null != id) {
            SysPostInfo postInfo = sysPostInfoService.getById(id);
            model.addAttribute("position", postInfo);
        } else {
            SysPostInfo postInfo = new SysPostInfo();
            postInfo.setStatus("Y");
            model.addAttribute("position", postInfo);
        }
        return "sys/position/edit";
    }
}

